class Solution:
    def maxRotateFunction(self, nums):
        n = len(nums)
        if n == 0:
            return 0
        S = sum(nums)
        F = 0
        for i, num in enumerate(nums):
            F += i * num
        F_max = F
        for j in range(1, n):
            F = F + S - n * nums[n-j]
            F_max = max(F_max, F)
        return F_max
if __name__ == '__main__':
    nums = [4, 3, 2, 6]
    print(Solution().maxRotateFunction(nums))